<template>
    <div class="login-wrap">
        <div style="width: 100%; text-align: center; margin-top: 100px">
            <p class="companyName">自有房产管理系统</p>
            <!-- <p class="companyName">自有房产管理系统测试</p> -->
        </div>
        <div class="ms-login">
            <div class="ms-title">账号登录</div>
            <el-form :model="param" :rules="rules" ref="login" class="ms-content" size="medium">
                <el-form-item prop="account">
                    <el-input
                        v-model="param.account"
                        placeholder="请输入账号"
                        prefix-icon="el-icon-user"
                        @keyup.enter.native="submitForm()"
                    >
                        <!-- <el-button slot="prepend" icon="el-icon-lx-people"></el-button> -->
                    </el-input>
                </el-form-item>
                <!-- @keyup.enter.native="submitForm()" -->
                <el-form-item prop="password">
                    <el-input
                        type="password"
                        placeholder="请输入密码"
                        v-model="param.password"
                        prefix-icon="el-icon-lock"
                        @keyup.enter.native="submitForm()"
                    >
                        <!-- <el-button slot="prepend" icon="el-icon-lx-lock"></el-button> -->
                    </el-input>
                </el-form-item>
                <div class="login-btn">
                    <el-button type="primary" @click="submitForm()" :loading="insertloading">登 录</el-button>
                </div>
            </el-form>
        </div>
    </div>
</template>

<script>
import { userLogin, dbnum, yzydbnum, szqrdbnum } from '@/api/index';
import store from '@/store';
export default {
    data: function () {
        return {
            insertloading: false,
            param: {
                account: '',
                password: ''
            },
            rules: {
                account: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
            }
        };
    },
    methods: {
        dbnum(data) {
            dbnum(data).then((res) => {
                console.log('待办', res);
                this.$store.commit('handledbnum1', res.data.swnum);
                this.$store.commit('handledbnum2', res.data.gdnum);
                this.$store.commit('handledbnum4', res.data.wtswnum);
            });
        },
        szqrdbnum(data) {
            szqrdbnum(data).then((res) => {
                console.log('收支待办', res.data);
            });
        },
        submitForm() {
            // sessionStorage.setItem('backgroundcolor', '#242f42');
            // sessionStorage.setItem('slidercolor', '#3E65EA');
            // 部署页面用的记得删除
            // this.$store.commit('handleuserName',this.param.account);
            // this.$store.commit('handlegfdw','');//3企业 2 经租资产管理部 1 房产经理部 0全部（type）
            // this.$router.push('/');
            // 部署页面用的记得删除结束
            // name 岗位 username人名
            this.$refs.login.validate((valid) => {
                if (valid) {
                    this.insertloading = true;
                    let data = {
                        account: this.param.account,
                        password: this.param.password
                    };
                    userLogin(data).then((res) => {
                        console.log(res);
                        if (res.code == 200) {
                            this.insertloading = false;
                            this.$store.commit('handleuserName', res.data.name);
                            this.$store.commit('handlerole', res.data.role);
                            this.$store.commit('handlecompany', res.data.company);
                            this.$store.commit('handletype', res.data.type); //3企业 2 经租资产管理部 1 房产经理部 0全部（type）
                            this.$store.commit('handleuserId', res.data.id);
                            this.$store.commit('handletoken', res.data.token);
                            this.$store.commit('handlerealName', res.data.username);
                            let type =
                                res.data.type == '1'
                                    ? '房产经理部'
                                    : res.data.type == '2'
                                    ? '经租资产管理部'
                                    : res.data.type == '3'
                                    ? '受托单位'
                                    : res.data.type == '0'
                                    ? '中心'
                                    : '';
                            this.$store.commit('handlegfdw', type); //3企业 2 经租资产管理部 1 房产经理部 0全部（type）
                            let userid = res.data.id;
                            this.dbnum(userid);
                            this.szqrdbnum(res.data.id);
                            if (res.data.role == '10011') {
                                this.yzydbnum(res.data.id);
                            } else {
                                this.$store.commit('handleyzydbnum', 'false');
                                if(res.data.type == '3'){
                                    this.$router.push('/stdwlist');
                                }else{
                                    this.$router.push('/');
                                }
                                
                            }
                        } else {
                            this.insertloading = false;
                            this.$message.error(res.message);
                        }
                    });
                } else {
                    this.insertloading = false;
                    this.$message.error('请输入账号和密码');
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        // 预转已待办数量
        yzydbnum(data) {
            yzydbnum(data).then((res) => {
                if (res.data.yzydbnum != 0) {
                    this.$store.commit('handledbnum3', res.data.yzydbnum);
                    this.$store.commit('handleyzydbnum', 'true');
                    this.$router.push('/');
                } else {
                    this.$store.commit('handledbnum3', 0);
                    this.$store.commit('handleyzydbnum', 'false');
                    this.$router.push('/');
                }
                console.log(res);
            });
        },
        // 测试方法
        csff() {
            let arr = [
                { name: '南京路303' },
                { name: '南京路304' },
                { name: '南京路304' },
                { name: '南京路306' },
                { name: '南京路303' },
                { name: '南京路308' },
                { name: '南京路309' },
                { name: '南京路-01' },
                { name: '南京路-9' },
                { name: '南京路-03' },
                { name: '南京路-8' }
            ];
            let array2 = this.arrsort(arr);
            console.log('array2', array2);
        },
        // 测试数组排序
        arrsort(arr) {
            let array1 = [];
            let array2 = [];
            arr.forEach((element, index) => {
                if (element.name.indexOf('-') != -1) {
                    array1.push(element);
                    array1.sort(function (a, b) {
                        let numA = parseInt(a.name.split('-')[1]);
                        let numB = parseInt(b.name.split('-')[1]);
                        return numA - numB;
                    });
                } else {
                    array2.push(element);
                }
            });
            return array1.concat(array2);
        },
        isChinese(s) {
            let reg = new RegExp('[\\u4E00-\\u9FFF]+', 'g');
            if (reg.test(s)) {
                alert('包含汉字');
            } else {
                alert('没汉字');
            }
        }
    },
    created() {
        // this.isChinese('012346')
        // this.csff();
        console.log('132456798', window.location.host);
    }
};
</script>

<style scoped>
/* 标头名称 */
.companyName {
    font-size: 54px;
    text-align: center;
    background: linear-gradient(#d9f0f5, #26d0fd);
    -webkit-background-clip: text;
    font-weight: 600;
    color: transparent;
    margin-bottom: 20px;
    /* margin-top: 140px; */
}

.appimg {
    font-weight: 700;
    color: #fff;
    text-align: center;
    position: fixed;
    bottom: 40px;
    right: 20px;
    height: 150px;
    width: 150px;
}

.appimg img {
    height: 100px;
    width: 100px;
}

.login-wrap {
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: url(../../assets/img/bgc1.png);
    /* background-color: #008A94; */
    background-size: 100%;
}

.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 32px;
    color: #ffffff;
    font-family: SourceHanSansCN-Regular, SourceHanSansCN;
    font-weight: 400;
    /* border-bottom: 1px solid #ddd; */
}

.ms-login {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 524px;
    /* margin: -190px 0 0 -262px; */
    margin-left: -302px;
    margin-top: -168px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    padding: 40px;
    overflow: hidden;
}

.ms-content {
    padding: 30px 30px;
}

.login-btn {
    text-align: center;
}

.login-btn button {
    background-color: #008a94;
    width: 100%;
    height: 48px;
    font-size: 28px;
    margin-bottom: 10px;
}

.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
</style>
<style>
.ms-login .el-input--medium .el-input__inner {
    height: 48px;
    line-height: 48px;
}
</style>